package edu.iscas.appcheckclient.service.network;

import android.content.Context;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

/**
 * Created by dell on 2015/12/2.
 */
public class RequestManager {
    private static RequestManager mInstance;
    private RequestQueue requestQueue;
    private static Context context;

    private RequestManager(Context ctx){
        context = ctx;
        requestQueue = getRequestQueue();
    }

    public static synchronized RequestManager getInstance(Context ctx){
        if(mInstance == null){
            mInstance = new RequestManager(ctx);
        }
        return mInstance;
    }


    public RequestQueue getRequestQueue(){
        if(requestQueue == null){
            requestQueue = Volley.newRequestQueue(context.getApplicationContext());
        }
        return requestQueue;
    }

    public <T> void addToRequestQueue(Request<T>req){
        getRequestQueue().add(req);
    }
}
